<script setup>
import {reactive} from "vue";
import uu from "@/util/uu";
import {ElMessage} from "element-plus";

let data = reactive(({
  // 所有的表单数据由它装入
  form:{},
  // 公司信息列表
  businessList : [] ,
}));
/**
 * 查询所有的公司信息
 */
const queryAll = () => {
  console.log("开始查询数据")
  console.log("传递的参数为"+JSON.stringify(data.form()))
  // http://localhost:8080
  uu.post("/hupCompany/pageList",data.form).then(result =>{
    data.businessList = result.data.list;
    data.form.pageNum = result.data.pageNum;
    data.form.pageSize = result.data.pageSize;
    data.total = result.data.total;
    console.log("接收到的数据为"+JSON.stringify(result.data));
  })
}
/*
  删除公司记录
 */
const delBusiness = () => {
  if (!ruleFormRef) return; // 为空就结束，直观效果就是不允许点击
  ruleFormRef.validate((valid, fields) => {
    if (valid) {
      // alert(data.form.claimReportId)
      uu.delete("/hupCompany/remove",{
        params:{
          id : data.form.id,
        }
      }).then(result =>{
        // alert(result.message)
        if (result.ok){
          data.success = true; // 显示成功提示
          ElMessage({
            message:result.message,
            type:"success",
          })
          // 关闭对话框
          data.dialogDelVisible = false;
          // 清楚数据
          data.form = {}
          // 刷新页面
          queryAll()
        }else {
          ElMessage.error(result.message)// 显示失败提示
        }
      })
    } else {
      console.log('error submit!', fields)
    }
  })
}
</script>

<template>
  <!-- 对话框 -->
  <el-dialog
      v-model="info.dialogVisible"
      :title="添加查勘信息"
      width="60%"
      :before-close="handleClose"
  >
    <el-form
        :model="info.form"
        label-width="120px"
        ref="ruleFormRef"
        :rules="rules"
    >
      <el-form-item label="选择调度任务" prop="dispatchTask">
        <el-select v-model="info.form.dispatchId" @change="selectDispatch" placeholder="请选择" style="width: 95%">
          <el-option v-for="item in info.dispatchList"
                     :label="item.claimReport.claimReportId+'---'+item.claimReport.contactPerson+'---'+item.claimReport.lossAddress"
                     :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="报案编号">
        {{ info.dispatchInfo.claimReportId }}
      </el-form-item>
      <el-form-item label="保单编号">
        <span
            v-if="info.dispatchInfo.insurancePolicy != null">{{ info.dispatchInfo.insurancePolicy.policyNumber }}</span>
      </el-form-item>
      <el-form-item label="产品名称">
        <span
            v-if="info.dispatchInfo.insurancePolicy != null">{{ info.dispatchInfo.insurancePolicy.insuranceType }}</span>
      </el-form-item>
      <el-form-item label="投保人">
        <span
            v-if="info.dispatchInfo.insurancePolicy != null">{{ info.dispatchInfo.insurancePolicy.insuredName }}</span>
      </el-form-item>
      <el-form-item label="投保金额">
        <span
            v-if="info.dispatchInfo.insurancePolicy != null">{{ info.dispatchInfo.insurancePolicy.insuranceAmount }}</span>
      </el-form-item>
      <el-form-item label="出险时间">
        <span v-if="info.dispatchInfo.claimReport != null">{{ info.dispatchInfo.claimReport.lossTime }}</span>
      </el-form-item>
      <el-row>
        <el-form-item label="查勘等级" prop="reportMethod">
          <el-select v-model="info.form.surveyType" :disabled="info.dispatchInfo.id == null" placeholder="请选择" style="width: 170px">
            <el-option label="一级" :value="一级"/>
            <el-option label="二级" :value="二级"/>
            <el-option label="三级" :value="三级"/>
          </el-select>
        </el-form-item>
        <el-form-item label="报损金额" prop="reportedLoss">
          <el-input v-model="info.form.reportedLoss" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="预估金额" prop="estimatedAmount">
          <el-input v-model="info.form.estimatedAmount" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="预估费用" prop="estimatedCost">
          <el-input v-model="info.form.estimatedCost" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="查勘日期" prop="surveyTime">
          <el-date-picker
              v-model="info.form.surveyTime"
              type="datetime"
              format="YYYY-MM-DD"
              value-format="YYYY-MM-DD"
              :disabled="info.dispatchInfo.id == null"
              style="width: 170px"
          />
        </el-form-item>
        <el-form-item label="估损数量" prop="disasterInfoId">
          <el-input v-model="info.form.estimatedNumber" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="受灾面积" prop="affectedArea">
          <el-input v-model="info.form.affectedArea" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="成灾面积" prop="affectedConfirmArea">
          <el-input v-model="info.form.affectedConfirmArea" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="绝产面积" prop="productionArea">
          <el-input v-model="info.form.productionArea" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
      </el-row>
      <el-row>
        <el-form-item label="死亡数量" prop="deathsNumber">
          <el-input v-model="info.form.deathsNumber" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="扑杀数量" prop="killQuantity">
          <el-input v-model="info.form.killQuantity" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
        <el-form-item label="实际指数" prop="surveyIndex">
          <el-input v-model="info.form.surveyIndex" :disabled="info.dispatchInfo.id == null" style="width: 170px"/>
        </el-form-item>
      </el-row>
      <el-form-item label="备注" prop="remark" style="width: 96%">
        <el-input v-model="info.form.remark" :disabled="info.dispatchInfo.id == null" type="textarea"/>
      </el-form-item>
    </el-form>
    <template #footer>
    <span class="dialog-footer">
      <el-button type="primary" @click="persistence(ruleFormRef)">保存信息</el-button>
    </span>
    </template>
  </el-dialog>
</template>

<style scoped>

</style>